﻿// owner 蒋家伟

#pragma once
// qt
#include <QWidget>
#include <QColor>
#include "IProgressBar.h"

class QPaintEvent;
namespace jsdk
{
    class ProgressBar : public QWidget, public IProgressBar
    {
        Q_OBJECT
    public:
        static OwnerPtr<ProgressBar> create(bool isAsynCalled, const QColor* pColor);
        ~ProgressBar() {}

        // 继承IProgressBar
        virtual void setPresent(uint8_t present) override;
        virtual void setFixedSize(uint16_t width, uint16_t height) override;
        virtual void show() override;
        virtual void close() override;
        virtual void setPrefix(const std::wstring& prefix) override;
        virtual void setFontSize(uint8_t fontWidth) override { m_fontWidth = fontWidth; };
        virtual void setColor(const QColor& color) { m_backgroundColor = color; };
        virtual void setFontColor(const QColor& color) { m_fontColor = color; };
        virtual const QWidget* getQWidget() const override { return this; };
        virtual QWidget* getQWidget() override { return this; };

    private:
        // 继承QWidget
        virtual void paintEvent(QPaintEvent* event) override;

        // owner
        explicit ProgressBar(bool isAsynCalled, const QColor& color);
    private:
        short m_present = 0;
        QColor m_backgroundColor;
        QColor m_fontColor;
        bool m_isAsynCalled = false;
        std::wstring m_prefix;
        uint8_t m_fontWidth = 14;
    };
}